#include <iostream>
#include <unordered_set>
#include <string>

using namespace std;

int base(string s, int b) {
    int res = 0;
    // 秦久韶算法
    for (auto x: s) {
        res = res * b + x - '0';
    }
    return res;
}

int main() {

    string x, y;

    cin >> x >> y;

    unordered_set<int> hash;

    for (int i = 0; i < x.size(); ++i) {
        string s = x;
        s[i] ^= 1;
        if (s.size() > 1 && s[0] == '0') {
            continue;
        }
        int value = base(s, 2);
        hash.insert(value);
    }

    for (int i = 0; i < y.size(); ++i) {
        for (int j = 0; j < 3; ++j) {
            if (y[i] - '0' != j) {
                string s = y;
                s[i] = j + '0';
                int value = base(s, 3);
                if (hash.count(value)) {
                    cout << value << endl;
                }
            }
        }
    }

    return 0;
}